<?php
	class Module_user_settings {
		public static function execute($params) {
			Auth::getInstance()->getPermis('client');

			if (!empty($params['info'])) {
				$user = Model_Auth::getInstance()->getUser(Auth::currLogin());

				if ($user->password != $params['info']['password']) {
					return array('error' => 'invalid_password');
				}

				if (!empty($params['info']['new_password'])) {
					if ($params['info']['new_password'] != $params['info']['repeat_password']) {
						return array('error' => 'password_not_equal');
					}

					$user->password = $params['info']['new_password'];

					$_SESSION[Auth::NAME]['password'] = $user->password;
				}

				$user->settings = array(
					'name'    => $params['info']['name'],
					'phone'   => $params['info']['phone'],
					'email'   => $params['info']['email'],
					'address' => $params['info']['address'],
				);

				Model_Auth::getInstance()->setUser($user);

				return array('ok' => true);
			}

			$vis = new Visual();

			return $vis->fetch('user/settings.twig');
		}


	}